#ifndef ROBOTSPORT_H
#define ROBOTSPORT_H

#include <QWidget>
#include <QButtonGroup>
#include "src/device/Robot/robothelper.h"
#include <QMessageBox>
#include <map>
#include "src/define/func_define.h"
#include "src/DataProvider/App/SysMembers.h"


namespace Ui {
class RobotSport;

}

namespace MultPos {

enum Direction{
    MX  = 0, // 对应TCP模式下dx
    MY,
    MZ
};

struct DataPackage{
    RobotPos pos = RobotPos::instance();
    int sportCount = 0;             // 运动次数
    int holdSpeed = 10;            // 起始速度
    int startSpeed = 10;            // 起始速度
    int endSpeed =   10;            // 起始速度
    double spacing = 4.0;
    bool isBase ;                   // pos是否在base下
    int genCount;                   // 生成的目标数量
    int speedSpacing = 10;

    Direction move;                 // 定义移动方向

    std::string smove;


public:
    void genVect(bool isHold);                 // 生成该点的序列
    void saveToLog();
    void genName();
    std::vector<RobotPos> getAllPos();

public:
    std::map<int ,std::vector<RobotPos> > pmap;     // 0.第几次
    std::string fileName;

};


/**
 * @brief oulerChange
 * @param start-------Base
 * @param b2b
 * @return
 */
static RobotPos oulerChange(RobotPos &start,RobotPos &b2b){
    RobotPos popp  = start;
    Matrix4d mb2b;
    pos2Matrix(b2b,mb2b,zyx);
    Matrix2pos(mb2b,b2b,zyz);
    popp = popp << b2b;
    return popp;
}

static std::vector<RobotPos> GenPos(bool isBase,Direction move,double spacing,RobotPos pos,int count){
    RobotPos tmp_pos = RobotPos::instance();
    std::vector<RobotPos> ret;

    /* 此处的作用为:如果是tool坐标系,在０处计算 */
    for(int i = 0;i<count;i++){
        if(isBase){
            tmp_pos = pos;
        }else{
            tmp_pos = RobotPos::instance();
        }

        switch (move) {
            case MX:
            tmp_pos.x += spacing*i;
            isBase ? ret.push_back(tmp_pos):
                     ret.push_back(oulerChange(pos,tmp_pos));
            break;
            case MY:
            tmp_pos.y += spacing*i;
            isBase ? ret.push_back(tmp_pos):
                     ret.push_back(oulerChange(pos,tmp_pos));
            break;
            case MZ:
            tmp_pos.z += spacing*i;
            isBase ? ret.push_back(tmp_pos):
                     ret.push_back(oulerChange(pos,tmp_pos));
            break;
        default:
            break;
        }
    }
    return ret;
}

}

class RobotSport : public QWidget
{
    Q_OBJECT

public:
    explicit RobotSport(QWidget *parent = nullptr);
    ~RobotSport();


public slots:

private slots:
    void on_pbPos_clicked();
    void on_pbAxle_clicked();
    void on_RxyzMove_clicked();

    void on_pb_run_clicked();

    void on_pb_Gen_clicked();

    void on_pb_SP_clicked();

private:
    Ui::RobotSport *ui;
    QButtonGroup *radios;

    void initDataPack();    // 初始化package
    void initUIs();

    int getRadioGroupIndex(); // 获取当前checkbox索引

    MultPos::DataPackage dataPack;      // 生成的数据集
};

#endif // ROBOTSPORT_H
